/*
 * @Author       : 吴豪
 * @Date         : 2021-12-4 15:56:22
 * @FilePath     : \book-manage-front\src\services\classification.ts
 * @Description  : 分类管理页面接口文件
 */

import type { Classification, ClassificationList, CreateClassificationType } from '@/dataType';
import { request } from 'umi';

/**
 * 1.获取分类列表
 * @returns 
 */
export async function getClassificationList(params: Classification) {
    return request<{ list: ClassificationList[]; rowsNum: number }>('/classificationManage/getClassificationList', { params })
}

/**
 * 2.获取父级分类列表
 * @returns 
 */
export async function getFatherClassificationList() {
    return request<{ aid: number; name: string }[]>('/classificationManage/getFatherClassificationList', {})
}

/**
 * 3.获取要修改的分类信息
 * @param params 
 * @returns 
 */
export async function getClassificationInfo(params: { aid: number }) {
    return request<{ name: string; fatherAid?: number }>('/classificationManage/getClassificationInfo', { params })
}

/**
 * 4.检查分类名称是否存在
 * @param params 4.
 * @returns 
 */
export async function checkClassificationNameExist(params: { aid: number; name: string }) {
    return request<{ isExist: boolean }>('/classificationManage/checkClassificationNameExist', { params })
}

/**
 * 5.检查闭环是否存在
 * @param params 
 * @returns 
 */
export async function checkClosedLoopExist(params: { aid: number; fatherAid?: number }) {
    return request<{ isExist: boolean }>('/classificationManage/checkClosedLoopExist', { params })
}

/**
 * 6.新增/修改分类信息
 * @param params 
 * @returns 
 */
export async function saveClassificationInfo(params: CreateClassificationType) {
    return request('/classificationManage/saveClassificationInfo', {
        data: params,
        method: 'POST'
    })
}

/**
 * 7.删除分类
 * @param params 
 * @returns 
 */
export async function deleteClassification(params: { aid: number }) {
    return request('/classificationManage/deleteClassification', {
        data: params,
        method: 'POST'
    })

}
